package eric.mpab.util;

import java.util.ArrayList;
import java.util.List;

import eric.mpab.domain.AccountDO;
import eric.mpab.model.Account;

public class AccountAssembler {
	public static Account assemble(AccountDO accountDO){
		if(accountDO == null) return null;

		Account account = new Account();
		account.setId(accountDO.getId());
		account.setType(accountDO.getType().name());
		account.setSymbol(accountDO.getSymbol().name());
		account.setName(accountDO.getName());
		account.setDescription(accountDO.getDescription());

		return account;
	}

	public static Account assemble(AccountDO accountDO, boolean includeChildren){
		Account account = assemble(accountDO);
		if(includeChildren){
			for(AccountDO childAccountDO : accountDO.getChildren()){
				account.getChildren().add(assemble(childAccountDO, includeChildren));
			}
		}
		return account;
	}

	public static List<Account> assemble(List<AccountDO> accountDOs, boolean includeChildren){
		List<Account> accounts = new ArrayList<Account>();
		for(AccountDO accountDO : accountDOs){
			accounts.add(assemble(accountDO, includeChildren));
		}
		return accounts;
	}
}
